package com.ruoyi.web.controller.statistics;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.statistics.domain.ResOpusLike;
import com.ruoyi.statistics.service.IResOpusLikeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作品喜欢Controller
 * 
 * @author ruoyi
 * @date 2021-12-20
 */
@RestController
@RequestMapping("/statistics/like")
public class ResOpusLikeController extends BaseController
{
    @Autowired
    private IResOpusLikeService resOpusLikeService;

    /**
     * 查询作品喜欢列表
     */
    @PreAuthorize("@ss.hasPermi('statistics:like:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResOpusLike resOpusLike)
    {
        startPage();
        List<ResOpusLike> list = resOpusLikeService.selectResOpusLikeList(resOpusLike);
        return getDataTable(list);
    }


    /**
     * 查询用户作品喜欢列表
     */
    @GetMapping("/viewList")
    public TableDataInfo viewList(ResOpusLike resOpusLike)
    {
        startPage();
        resOpusLike.setUserId(getUserId());
        List<ResOpusLike> list = resOpusLikeService.selectResOpusLikeViewList(resOpusLike);
        return getDataTable(list);
    }

    /**
     * 导出作品喜欢列表
     */
    @PreAuthorize("@ss.hasPermi('statistics:like:export')")
    @Log(title = "作品喜欢", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResOpusLike resOpusLike)
    {
        List<ResOpusLike> list = resOpusLikeService.selectResOpusLikeList(resOpusLike);
        ExcelUtil<ResOpusLike> util = new ExcelUtil<ResOpusLike>(ResOpusLike.class);
        util.exportExcel(response, list, "作品喜欢数据");
    }

    /**
     * 获取作品喜欢详细信息
     */
    @PreAuthorize("@ss.hasPermi('statistics:like:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(resOpusLikeService.selectResOpusLikeById(id));
    }

    /**
     * 新增作品喜欢
     */
    @Log(title = "作品喜欢", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResOpusLike resOpusLike)
    {
        resOpusLike.setUserId(getUserId());
        return toAjax(resOpusLikeService.insertResOpusLike(resOpusLike));
    }

    /**
     * 修改作品喜欢
     */
    @PreAuthorize("@ss.hasPermi('statistics:like:edit')")
    @Log(title = "作品喜欢", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResOpusLike resOpusLike)
    {
        return toAjax(resOpusLikeService.updateResOpusLike(resOpusLike));
    }

    /**
     * 修改作品(一键已读)
     */
    @PreAuthorize("@ss.hasPermi('statistics:like:edit')")
    @Log(title = "作品喜欢", businessType = BusinessType.UPDATE)
    @PutMapping("/modifyState/{ids}")
    public AjaxResult modifyState(@PathVariable Long[] ids)
    {
        return toAjax(resOpusLikeService.updateResOpusStatusLike(ids));
    }

    /**
     * 删除作品喜欢
     */
    @Log(title = "作品喜欢", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resOpusLikeService.deleteResOpusLikeByIds(ids));
    }
}
